package cuit.campus.taskRunning.commons.utils;


import com.aliyun.credentials.Client;

import com.aliyun.credentials.models.Config;
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import com.aliyun.tea.TeaException;

import java.util.Random;


public class SmsUtil {

//    private static final String ACCESS_KEY_ID = "";//AccessKey自己账号的
//    private static final String ACCESS_KEY_SECRET = "";
//    private static final String ENDPOINT = "dysmsapi.aliyuncs.com";//固定死
//    private static final String SIGNNAME = "";//签名名称
//    private static final String TCODE = "";//模版的编号

//    public static String  sendSms(String phoneNumbers) throws Exception {
//
//        String code=generateVerificationCode();
//
//        Config config = new Config()
//                .setAccessKeyId(ACCESS_KEY_ID)
//                .setAccessKeySecret(ACCESS_KEY_SECRET)
//                .setEndpoint(ENDPOINT);
//
//        Client client = new Client(config);
//        SendSmsRequest sendSmsRequest = new SendSmsRequest()
//                .setPhoneNumbers(phoneNumbers)
//                .setSignName(SIGNNAME)
//                .setTemplateCode(TCODE)
//                //此处是设计模版的时候预留的变量${code}就验证码，用下面的随机生成4位数字传入
//                .setTemplateParam(String.format("{\"code\":\"%s\"}", code));
//
//        try {
//            SendSmsResponse sendSmsResponse = client.sendSms(sendSmsRequest);
//            return code;
//        } catch (TeaException error) {
//            return "失败";
//        }
//    }


    /**
     * 验证码随机四位
     */
    public static String generateVerificationCode() {
        // 生成四位数字验证码
        Random random = new Random();
        int code = random.nextInt(10000); // 随机生成 0 到 9999 的整数
        return String.format("%06d", code); // 保证生成的是四位数字，不足四位时前面补0
    }
}

